package priv.pront.code.national.acwing.dp.bags;

import java.util.Scanner;

public class Acwing1024_装箱问题 {

    static int V, n;
    static int[] v;
    static int[] dp;
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        V = scanner.nextInt();
        n = scanner.nextInt();
        v = new int[n + 1];
        dp = new int[V + 1];
        for(int i = 1; i <= n; i++){v[i] = scanner.nextInt();}
        for(int i = 1; i <= n; i++){
            for(int j = V; j >= 1; j--){
                if(j - v[i] >= 0){
                    dp[j] = Math.max(dp[j], dp[j - v[i]] + v[i]);
                }
            }
        }
        System.out.println(V - dp[V]);
    }
}
